package org.hsc.httpProxy;


import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HttpProtocolEncoder  extends ProtocolEncoderAdapter { 
	private static Logger logger = LoggerFactory.getLogger(HttpProtocolEncoder.class); 
	
	@Override
	public void encode(IoSession session, Object message,ProtocolEncoderOutput out) throws Exception {
		if (message instanceof IoBuffer) {
			IoBuffer buf=(IoBuffer) message;
			byte[] bts=buf.array();
			logger.warn("数据写入:"+new String(bts));
			out.write(bts);
			logger.warn("数据写入完成！");
    	}else{
    		logger.warn("异常数据："+message);
    	}
		session.close(false);
	}

}
